package cn.lingyangwl.agile.misc.order.controller;

import cn.lingyangwl.agile.misc.order.model.*;
import cn.lingyangwl.agile.misc.order.service.*;
import cn.lingyangwl.framework.core.response.*;
import cn.lingyangwl.framework.validation.group.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 订单
 * 
 * @author shenguangyang
 */
@Api(tags = "订单")
@RestController
@RequestMapping("/order")
public class OrderController {
    @Resource
    private OrderService orderService;

    @ApiOperation(value = "分页订单")
    @GetMapping("/page")
    public Resp<IPage<OrderResp>> pageOrder(@Validated OrderQueryReq req) {
        return Resp.ok(orderService.pageOrder(req));
    }

    @ApiOperation(value = "通过id查找订单")
    @GetMapping("/get")
    public Resp<OrderResp> getOrder(@RequestParam(value = "id") Long id) {
        return Resp.ok(orderService.getOrder(id));
    }

    @ApiOperation(value = "保存订单")
    @PostMapping("/save")
    public Resp<?> saveOrder(@Validated(InsertGroup.class) @RequestBody OrderSaveReq req) {
        return Resp.ok(orderService.saveOrder(req));
    }

    @ApiOperation(value = "更新订单")
    @PostMapping("/update")
    public Resp<?> updateOrder(@Validated(UpdateGroup.class) @RequestBody OrderSaveReq req) {
        return Resp.ok(orderService.updateOrder(req));
    }

    @ApiOperation(value = "批量删除订单")
    @DeleteMapping("/batchDelete")
    public Resp<?> batchDeleteOrder(@RequestParam(value = "ids") List<Long> ids) {
        return Resp.ok(orderService.batchDeleteOrder(ids));
    }

    @ApiOperation(value = "删除订单")
    @DeleteMapping("/delete")
    public Resp<?> deleteOrder(@RequestParam(value = "id") Long id) {
        return Resp.ok(orderService.deleteOrder(id));
    }
}
